package org.eenie.core.base.viewbinding

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import org.eenie.core.base.BaseDialogFragment
import org.eenie.core.base.BaseFragment

abstract class BaseBindingDialogFragment< BD : ViewBinding> : BaseDialogFragment() {

    lateinit var binding: BD


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return if (getLayoutRes() > 0) {
            super.onCreateView(inflater, container, savedInstanceState)
        } else {
            binding = providerBinding(inflater,savedInstanceState)
            binding.root
        }
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        if (::binding.isInitialized) {
            initUI(binding)
        }
    }

    override fun getLayoutRes(): Int = -1


    override fun initUI(mRootView: View) {

    }

    abstract fun providerBinding(inflater: LayoutInflater, savedInstanceState: Bundle?): BD

    abstract fun initUI(binding: BD)

}